# -*- coding: utf-8 -*-
# @Time : 2018/12/21 10:31
# @Author : Administrator
# @File : csv_read.py
# @Project : python_demo
# @title : 读取CSV数据文件
class Data_Read():
    def read_csv(self,filename):
        with open(filename) as f:
            lines=f.readlines()
            # print(lines)
            # print(lines[0].strip())
            key1=lines[0].strip().split(",")[0]
            # print(key1)
            key2 = lines[0].strip().split(",")[1]
            # print(key2)
            # print(lines[1].strip())
            # print(lines[2].strip())
            list=[]
            for i in range(1,len(lines)):
                # print(i)
                # print(lines[i].strip().split(",")[0])
                # print(lines[i].strip().split(",")[1])
                username=lines[i].strip().split(",")[0]
                password = lines[i].strip().split(",")[1]
                dict={}
                dict[key1]=username
                dict[key2] = password
                list.append(dict)
            # print(list)
            return list
if __name__ == '__main__':
    d=Data_Read()
    result=d.read_csv("data.csv")

    print(result)
    print(result[0])
    print(result[0]["username"])
    print(result[0]["password"])
